package com.yh.supergo.page.config;

import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @ClassName GoodsMap
 * @Description TODO
 * @Author 0715-YuHao
 * @Date 2020/11/21 15:42
 */
@Component
public class GoodsLock {

    private ConcurrentHashMap<Long, ReentrantLock> lockMap = new ConcurrentHashMap<>();

    public ReentrantLock getLock(Long spuId) {
        return lockMap.getOrDefault(spuId, new ReentrantLock());
    }

    public void removeLock(Long spuId) {
        lockMap.remove(spuId);
    }
}
